package com.bulemobi.activity.ac_feedback;

import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import com.bulemobi.net.tsz.afinal.FinalHttp;
import com.bulemobi.net.tsz.afinal.annotation.view.ViewInject;
import com.bulemobi.net.tsz.afinal.http.AjaxCallBack;
import com.bulemobi.net.tsz.afinal.http.AjaxParams;
import com.bulemobi.urlCentre.UrlCentre;
import com.bulemobi.view.BaseActivity;
import com.bulemobi.view.titleView.ActionBarView;
import com.jsyh.hcb.R;

public class AcFeedback extends BaseActivity {
    @ViewInject(id = R.id.bt_confirm)
    Button bt_confirm;
    @ViewInject(id = R.id.actionBar)
    ActionBarView actionBarView;
    @ViewInject(id = R.id.ed_content)
    EditText ed_content;
    @ViewInject(id = R.id.tv_hint)
    TextView tv_hint;

    private TextWatcher watcher = new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {

        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            if(s.toString().length()>0){
                tv_hint.setVisibility(View.GONE);
            }else {
                tv_hint.setVisibility(View.VISIBLE);
            }
        }

        @Override
        public void afterTextChanged(Editable s) {

        }
    };

	@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.ac_feedback);
        initView();
    }

    private void requestHttp(String url,AjaxParams params){
        FinalHttp http = new FinalHttp();
        http.post(url,params,new AjaxCallBack<Object>() {
            @Override
            public void onStart() {
                showProgressDialog();
                super.onStart();
            }

            @Override
            public void onSuccess(Object o) {
                Log.d("OnSuccess",o.toString());
                closeProgressDialog();
                super.onSuccess(o);
            }

            @Override
            public void onFailure(Throwable t, int errorNo, String strMsg) {
                closeProgressDialog();
                super.onFailure(t, errorNo, strMsg);
            }
        });
    }

    private void initView(){
        actionBarView.title.setText("我要说说");
        ed_content.addTextChangedListener(watcher);
        bt_confirm.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                AjaxParams params = new AjaxParams();
                params.put("noteContent",ed_content.getText().toString());
                params.put("TerminalType", UrlCentre.TerminalType);
                params.put("UserType", UrlCentre.UserType);
                params.put("ChannelId", UrlCentre.ChannelId);
                requestHttp(UrlCentre.UserSuggest,params);
            }
        });
    }

}
